package org.hxuhao;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.hxuhao.dao.UserMapper;

import java.io.IOException;
import java.io.InputStream;

public class Hello {
    public static void main(String []args) throws IOException, InterruptedException {
        String resource = "mybatis/mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        try (SqlSession session = sessionFactory.openSession()) {
            Long id = 1L;
            UserMapper user = session.getMapper(UserMapper.class);
            System.out.println(user.getById(id));
        }


        new Thread(()->{
            try (SqlSession session = sessionFactory.openSession()) {
                Long id = 1L;
                UserMapper user = session.getMapper(UserMapper.class);
                System.out.println(user.getById(id));
            }
        }).start();


        Thread.sleep(1000*1000);

    }
}
